package com.dcits.iweibo.monitor.runner;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

@Slf4j
@Component
public class MonitorRunner implements ApplicationRunner {

    @Autowired
    Environment environment;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        String port = environment.getProperty("server.port");
        if (port == null) {
            port = "";
        }
        String contextPath = environment.getProperty("server.servlet.context-path");
        if (contextPath == null) {
            contextPath = "";
        }
        log.warn("********************************************************************************");
        log.warn("*****************************监控应用启动成功！***************************************");
        log.warn("************监控页面请访问：http://{}:{}{}",hostAddress,port,contextPath);
        log.warn("********************************************************************************");
    }
}
